home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16586 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  64 lines

  1. Path: ix.netcom.com!news
  2. From: giuliano@ix.netcom.com(Giuliano Carlini)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: "Pure virtual function called" error with Sparcworks
  5. Date: 11 Apr 1996 06:59:29 GMT
  6. Organization: Netcom
  7. Message-ID: <4kiakh$mjq@dfw-ixnews8.ix.netcom.com>
  8. References: <316B8607.41C67EA6@jpmorgan.com>
  9. NNTP-Posting-Host: lbx-ca7-14.ix.netcom.com
  10. X-NETCOM-Date: Thu Apr 11  1:59:29 AM CDT 1996
  11.  
  12. In <316B8607.41C67EA6@jpmorgan.com> Oliver Peck
  13. <peck_oliver@jpmorgan.com> writes: 
  14. >
  15. >I am using V4.0.1 of the Sparcworks C++ compiler.
  16. >
  17. >A program is occasionally crashing with the message:-
  18. >
  19. >"****  Pure virtual function called"
  20. >
  21. >Does anyone know what this may mean?
  22. >
  23. >
  24. >Thanks in advance.
  25. >
  26. >Oliver
  27.  
  28. This usually means you've done something like this:
  29.  
  30. class Base {
  31. public:
  32.     virtual void foo() = 0;
  33. };
  34.  
  35. class Derived : public Base {
  36.     virtual void foo(){ ... };
  37. };
  38.  
  39. main()
  40. {
  41.     Derived*    d;
  42.  
  43.     d = new Derived;
  44.     delete d;
  45.     d->foo();
  46. }
  47.  
  48. What happens is that when you delete D, that first calls the destructor
  49. for Derived, and then that for Base. For reasons that get ugly, most
  50. vendors replace the v-table pointer at the start of the destructor with
  51. the v-table for that class. So, Base:~Base replaces d's v-table pointer
  52. with the v-table for class Base. But, class Base doesn't provide an
  53. implementation for foo. So, there is nothing for the foo entry in the
  54. Base v-table to point to. Or, so you'd think. What happens is that the
  55. compiler secretely provided Base::foo for you. It shrieks:
  56.     ****  Pure virtual function called
  57. and then exits.
  58.  
  59. There are other ways to get this error, but this is the most common
  60. that I've seen.
  61.  
  62. g
  63.  
  64.